/**
* 显示消息提示框
* @param content 提示的标题
*/
export function toast(content) {
  uni.showToast({
    icon: 'none',
    title: content
  })
}

/**
* 显示模态弹窗
* @param content 提示的标题
*/
export function showConfirm(content) {
  return new Promise((resolve, reject) => {
    uni.showModal({
      title: '提示',
      content: content,
      cancelText: '取消',
      confirmText: '确定',
      success: function(res) {
        resolve(res)
      }
    })
  })
}

export function formatDate(date) {
  const pad = (num) => String(num).padStart(2, '0'); // 补零
  const year = date.getFullYear();
  const month = pad(date.getMonth() + 1); // 月份从0开始
  const day = pad(date.getDate());
  const hours = pad(date.getHours());
  const minutes = pad(date.getMinutes());
  const seconds = pad(date.getSeconds());
  // return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  // 冯灏
  // console.log(date)
	// const UTC_time = date.replace('T', ' ').slice(0, 19)
	// const beijing_time_hour = pad(Number(UTC_time.slice(11, 13)) + 8)
	// const beijing_time = UTC_time.slice(0, 10) + ' ' +  beijing_time_hour + UTC_time.slice(13, 19)
	// console.log(beijing_time)
	// console.log(UTC_time, beijing_time_hour)
    // return beijing_time
	return `${year}-${month}-${day}`;
}
/**
* 参数处理
* @param params 参数
*/
export function tansParams(params) {
  let result = ''
  for (const propName of Object.keys(params)) {
    const value = params[propName]
    var part = encodeURIComponent(propName) + "="
    if (value !== null && value !== "" && typeof (value) !== "undefined") {
      if (typeof value === 'object') {
        for (const key of Object.keys(value)) {
          if (value[key] !== null && value[key] !== "" && typeof (value[key]) !== 'undefined') {
            let params = propName + '[' + key + ']'
            var subPart = encodeURIComponent(params) + "="
            result += subPart + encodeURIComponent(value[key]) + "&"
          }
        }
      } else {
        result += part + encodeURIComponent(value) + "&"
      }
    }
  }
  return result
}